package com.zang;

/**
 * @Author: ZVerify
 * @Description: TODO 简单二分
 * @DateTime: 2022/9/30 9:54
 **/
public class BinarySearch {

    public int search(int[] nums, int target) {

        int i = 0,j = nums.length-1;

        while (i<=j){

            int middle = i + (j-i)>>1;
            if (nums[middle]>target){
                j = middle-1;
            }else if (nums[middle]<target){
                i = middle+1;
            }else {
                return middle;
            }
        }
       return -1;
    }
}
